home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swagd_f.zip / FILES.SWG / 0015_File Exist in Assembler.pas < prev    next >
Pascal/Delphi Source File  |  1993-06-08  |  1KB  |  42 lines

  1. {$A+,B-,D+,E+,F-,G+,I+,L+,N-,O-,P-,Q-,R-,S+,T-,V-,X+,Y+}
  2. {$M 16384,0,655360}
  3.  
  4. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  5. Msg  : 193 of 292
  6. From : Wilbert van Leijen                  2:281/256.14         14 May 93  19:29
  7. To   : Vince Laurent                       1:382/10.0
  8. Subj : a few questions...
  9. ────────────────────────────────────────────────────────────────────────────────
  10. 07 May 93, Vince Laurent writes to All:
  11.  
  12.  VL> 1. What is the quickest way to check for the existance of a file?
  13.  VL>    I am going to be running the application on a network and would
  14.  VL>    like to minimize network traffic.
  15.  
  16. You cannot bypass the file server for this purpose, the reason should be
  17. obvious.  So peer-to-peer communication protocols are out.
  18.  
  19. Suggestion: obtain the file's attributes using INT 21h, AH=43h, DS:DX -> ASCIIZ
  20. filename.
  21. If this call sets the carry flag, the file doesn't exist.  Otherwise, it does.
  22. Advantage: no need for an attempt to open it.}
  23.  
  24. Function FileExist(filename : String) : Boolean; Assembler;
  25.  
  26. ASM
  27.         PUSH   DS
  28.         LDS    SI, [filename]      { make ASCIIZ }
  29.         XOR    AH, AH
  30.         LODSB
  31.         XCHG   AX, BX
  32.         MOV    Byte Ptr [SI+BX], 0
  33.         MOV    DX, SI
  34.         MOV    AX, 4300h           { get file attributes }
  35.         INT    21h
  36.         MOV    AL, False
  37.         JC     @1                  { fail? }
  38.         INC    AX
  39. @1:     POP    DS
  40. end;  { FileExist }
  41.  
  42.